<template>

  <el-container>
    <!--侧边栏-->
    <el-aside width="200px">
      <SideMenu></SideMenu>
    </el-aside>
    <!--侧边栏-->

    <el-container>
      <!--下拉首页栏-->
      <el-header style="height: 55px;">
        <Strong>后台管理系统</Strong>
        <div class="header-avatar block">
          <el-avatar class="el-avatar" size="medium" :src="avatar"></el-avatar>
          <!--下拉组件-->
          <el-dropdown>
            <span class="el-dropdown-link">
              欢迎 {{userInfo.adminName}}<i class="el-icon-arrow-down el-icon--right"></i>
            </span>

            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item :underline="false">
                <router-link :to="{name: 'adminCentral'}">个人中心</router-link>
              </el-dropdown-item>
              <el-dropdown-item @click.native="logout">退出</el-dropdown-item>
            </el-dropdown-menu>

          </el-dropdown>
          <!--下拉组件-->

        </div>
      </el-header>

        <el-main>

        <div style="margin: 0 15px;">
        <router-view></router-view>
        </div>
        </el-main>
    </el-container>
  </el-container>
</template>

<script>
import SideMenu from "./comp/adminSideMenu";
import Central from "./adminCentral"
export default {
  name: "adminHome",
  //声明使用的组件
  components: {
    SideMenu,Central
  },
  data() {
    return {
      avatar: 'http://localhost:8808/static/source/admin/admin.jpg',
      sysInfoServer: 'ws://localhost:8808/notification/',

      userInfo: {
        adminName: '',
        adminID: 0,
        authority: 0,
        creator: 0,
        email: '',
        phone: ','
      }
    }
  },
  methods: {
    accessAdmin(){
      let url = 'api/admin/accessAdmin'
      const self = this;
      this.$axios.get(url).then((res)=>{
        const entity = res.data.data;
        self.userInfo = entity;
      }).catch(err => {
        console.error(err)
        this.$router.push("/adminLogin")
      })
    },
    logout(){
      this.$axios.get("api/unLogin/logout").then(res => {
        console.log(res.data.data)
        localStorage.clear()
        sessionStorage.clear()
        this.$store.commit("resetState")
        this.$router.push("/adminLogin")
      })
    }
  },
  created() {
    this.accessAdmin();
  }
}
</script>

<style scoped>
  .el-container {
    padding: 0;
    margin: 0;
    height: 100%;
  }
  .header-avatar {
    float: right;
    width: 210px;
    display: flex;
    justify-content: space-around;
    align-items: center;
  }
  .el-dropdown-link {
    cursor: pointer;
  }
  .el-header {
    background-color: #17B3A3;
    color: #333;
    text-align: center;
    line-height: 60px;
  }
  .el-aside {
    background-color: #D3DCE6;
    color: #333;
    line-height: 200px;
  }
  .el-main {
    color: #333;
    padding: 0;
  }
  a {
    text-decoration: none;
  }
  Strong{
    font-size: 25px;
  }
</style>